package IOperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements Operation{
    public void work(BookList bookList){
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的书名：");
        String name = scanner.nextLine();

        int choice = bookList.getUsedSize();
        for (int i = 0; i < choice; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                for (int j = i; j < choice -1; j++) {
                    Book book = bookList.getBook(j+1);
                    //bookList.getBook(i) = book;
                    bookList.setBook(i,book);
                }
                bookList.setBook(choice-1,null);
                bookList.setUsedSize(choice-1);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("没有你要删除的图书!");
    }

}
